import { ref } from "vue";
//1.数据双向绑定
//(1)定义类型
interface User {
  email: string;
  password: string;
}
//(2)配置类型
export const loginUser = ref<User>({
  email: "",
  password: "",
});

//2.表单校验
//(1)定义类型
interface Rules {
  email: {
    type: string;
    message: string;
    required: boolean;
    trigger: string;
  }[];
  password: (
    | {
        required: boolean;
        message: string;
        trigger: string;
        min?: undefined;
        max?: undefined;
      }
    | {
        min: number;
        max: number;
        message: string;
        trigger: string;
        required?: undefined;
      }
  )[];
}
//(2)配置类型
export const rules = ref<Rules>({
  email: [
    {
      type: "email",
      message: "邮箱不能为空",
      required: true,
      trigger: "blur",
    },
  ],
  password: [
    {
      required: true,
      message: "密码不能为空",
      trigger: "blur",
    },
    {
      min: 6,
      max: 8,
      message: "密码长度为6-8位",
      trigger: "blur",
    },
  ],
});
